<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>记账</title>
  <!--[if lt IE 9]>
  <script src="libs/html5shiv.min.js"></script>
  <script src="libs/respond.min.js"></script>
  <![endif]-->
  <script src="libs/jquery-1.12.1.min.js"></script>
  <link href="libs/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
  <script src="libs/bootstrap-3.3.6/js/bootstrap.min.js"></script>
  <script src="libs/handlebars.min.js" type="text/javascript"></script>
  <script src="libs/d3.v3.min.js" type="text/javascript"></script>
  <script src="libs/nv.d3.min.js" type="text/javascript"></script>
  <link href="libs/bootstrap-3.3.6/css/nv.d3.min.css" rel="stylesheet">
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="page-header">
				<h2>
					<strong>个人账册</strong>
				</h2>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="col-md-8">
			<ul class="nav nav-pills">
				<li><a href="index.html">首页</a></li>
				<li><a href="shouru.html">新加收入</a></li>
				<li><a href="zhichu.html">新加支出</a></li>
				<li><a href="query.html">查询</a></li>
				<li class="active"><a href="tongji.html">统计</a></li>
				<li><a href="#">用户：<span id="nickname"></span></a></li>
			    <button id="tuichu">用户退出</button>
			</ul>
		</div>
	</div>


	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<hr />
			</div>
		</div>
	</div>



	<div class="container">
		<div class="row">
			<div class="col-md-6">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<p>当月收入</p>
					</div>
					<div class="panel-body">
						<h1 id="text3"></h1>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<p>当月支出</p>
					</div>
					<div class="panel-body">
						<h1 id="text4"></h1>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<p>最近的四笔收入</p>
					</div>
					<div class="panel-body" id="list3"></div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<p>最近的四笔支出</p>
					</div>
					<div class="panel-body" id="list4"></div>
				</div>
			</div>
		</div>
		<div class="container">
			<div class="row">
				<div class="col_md_12" id="chart">
					<p>
					<br />
					<hr />
					<strong>收入统计</strong>
					<svg style="height: 300px; width: 50%"></svg>
					<br>
					</p>
				</div>
			</div>
		</div>
		<div class="container">
			<div class="row">
				<div class="col_md_12" id="chart1">
					<p>
					<br />
					<hr />
					<strong>支出统计</strong>
					<svg style="height: 300px; width: 50%"></svg>
					<br>
					</p>
				</div>
			</div>
		</div>
	</div>


	<script type="text/x-handlebars-template" id="template">
{{#each item3}}
<div class="panel panel-default col-md-3">
  <div class="panel-body">
  <dl>
  <dt>类别</dt><dd>{{kind}}</dd>
  <dt>总和</dt><dd>{{si}}</dd>
  <dt>平均</dt><dd>{{avmi}}</dd>
  </dl>
  </div>
</div>
{{/each}}
</script>
	<script type="text/x-handlebars-template" id="template1">
{{#each item4}}
<div class="panel panel-default col-md-3">
  <div class="panel-body">
  <dl>
  <dt>类别</dt><dd>{{kind}}</dd>
  <dt>总和</dt><dd>{{so}}</dd>
  <dt>平均</dt><dd>{{avmo}}</dd>
  </dl>
  </div>
</div>
{{/each}}
</script>



</body>
<script type="text/javascript">
	$(function() {
		
		$.getJSON('queryUsers.action', function(res) {
			//console.log(res);
			$('#nickname').text(res.nk);
		})
		
		$('#tuichu').click(function() {
			$.post('tuichu.action', function(res, status) {
				if ('OK' == res) {
					alert('退出成功');
				}
				window.location.href = "login.html";
			});
		});
		
		
		$.getJSON('queryyin.action', function(res) {
			//console.log(res);  
			$('#text3').text(res.wode)
		})
		$.getJSON('queryyout.action', function(res) {
			//console.log(res);  
			$('#text4').text(res.woqu)
		})
		$.getJSON('queryUsers.action', function(res) {
			//console.log(res);
			$('#nickname').text(res.nk);
		})
		$.getJSON('query_kindsum.action', function(res) {
			var data = {
				'item3' : res
			};
			var t = Handlebars.compile($('#template').html());
			$('#list3').html(t(data));
		})
		$.getJSON('query_kindping.action', function(res) {
			var data = {
				'item4' : res
			};
			var t = Handlebars.compile($('#template1').html());
			$('#list4').html(t(data));
		})

		$.getJSON('query_kindsum.action', function(res) {
			nv.addGraph(function() {
				var chart = nv.models.pieChart().x(function(d) {
					return d.kind
				}).y(function(d) {
					return d.si
				}).showLabels(true).labelType('percent');
				d3.select("#chart svg").datum(res).transition().duration(350)
						.call(chart);
				return chart;
			})
		})
		$.getJSON('query_kindping.action', function(res) {
			nv.addGraph(function() {
				var chart1 = nv.models.pieChart().x(function(d) {
					return d.kind
				}).y(function(d) {
					return d.so
				}).showLabels(true).labelType('percent');
				d3.select("#chart1 svg").datum(res).transition().duration(350)
						.call(chart1);
				return chart1;
			})
		})

	})
</script>
</html>